package datastruct;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: DataStructuresAndAlgorithms
 * @description: 内存分析案例
 * @author: zhang
 * @create: 2020-03-16 15:38
 */
public class OOMObjectDemo {

    static class OOMObject {
        public byte[] placeholder = new byte[64 * 1024];

    }
    public static void fillHeap(int num) throws InterruptedException {
        List<OOMObject> list = new ArrayList<>();
        for (int i = 0; i < num; i++) {
            Thread.sleep(100);
            list.add(new OOMObject());
            System.out.println("第"+(i+1)+"次分配内存");
        }
        System.gc();
    }

    public static void main(String[] args) throws InterruptedException {
        fillHeap(10000);
    }
}
